package cn.pconline.officialclub.web;

import cn.pconline.autoclub.entity.User;
import cn.pconline.autoclub.util.WebUtils;
import cn.pconline.officialclub.entity.OClub;
import cn.pconline.officialclub.service.OClubService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 *
 * @author xulin
 */
@Controller
@RequestMapping(value = "/brand/topic")
public class OTopicController extends WebKit {

    @Autowired
    private OClubService oClubService;

    /**
     * 发帖
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/post.do", method = RequestMethod.GET)
    public String post(HttpServletRequest request, HttpServletResponse response) {
        long oClubId = WebUtils.paramOClubId(request);
        OClub oClub = oClubService.findValidClub(oClubId);
        if (oClub == null) {
            return redirect404(response);
        }
        User user = checkUser(request, response);
        if(user == null){
            return null;
        }
        if((oClub.isMustBindPhone() && StringUtils.isBlank(user.getBindPhone())) || oMemberService.isUserLock(user,oClubId)){
           redirect403(response);
           return "/template/common/noAuthPage";
        }
        request.setAttribute("oClub", oClub);
        request.setAttribute("fId", oClub.getForumId());
        String type = request.getParameter("type");
        request.setAttribute("type", type);
        request.setAttribute("returnUrl", systemConfig.getBrandClubRoot() + "/" + oClub.getUrl() + "/topic/");
        return "/template/official/pc/topic/post";
    }
}
